<?php
/**
 * Created by PhpStorm.
 * User: 13790
 * Date: 2018/3/21
 * Time: 23:15
 */

namespace app\admin\controller;

use think\Controller;

class Login extends Controller {

    public function login(){
        if(request()->isPost()){

        $data=input('post.');

        $res=db('Admin')->where('admin_user','=',$data['admin_user'])->find();
        if(!$res){
            $this->error('用户名不存在或被禁用');
        }

        if($res['admin_pass'] == md5($data['admin_pass'])){

            session('admin_user',$res['admin_user']);
            session('admin_id',$res['id']);
            session('admin_role',$res['admin_role']);

            $this->success('登录成功','Index/index');
        }
        $this->error('密码错误');
        }
        return view();
    }
    public function logout(){
        session('admin_user',null);
        session('admin_id',null);
        return redirect('login');
    }

}